class Student {
    private name: string;
    private rollNo: number;
    constructor(name: string, rollNo: number) {
        this.name = name;
        this.rollNo = rollNo;
    }
    public getName(): string {
        return this.name;
    }
    public setName(name: string): void {
        this.name = name;
    }
    public getRollNo(): number {
        return this.rollNo;
    }
    public setRollNo(rollNo: number): void {
        this.rollNo = rollNo;
    }
}

interface StudentDAO {
    getAllStudents(): Student[];
    getStudent(rollNo: number): Student | null;
    updateStudent(student: Student): void;
    deleteStudent(student: Student): void;
}

class StudentDAOImpl implements StudentDAO {
    private students: Student[];
    public constructor() {
        this.students = [];
        const student1: Student = new Student("John", 1);
        const student2: Student = new Student("Mary", 2);
        const student3: Student = new Student("Tom", 3);
        this.students.push(student1);
        this.students.push(student2);
        this.students.push(student3);
    }
    public deleteStudent(student: Student): void {
        const index: number = this.students.indexOf(student);
        if (index !== -1) {
            this.students.splice(index, 1);
        }
        console.log(`Student ${student.getRollNo()} deleted successfully.`);
    }
    public getAllStudents(): Student[] {
        return this.students;
    }
    public getStudent(rollNo: number): Student | null {
        return this.students.find(student => student.getRollNo() === rollNo) || null;
    }
    public updateStudent(student: Student): void {
        const studentToUpdate: Student | null = this.getStudent(student.getRollNo());
        if (studentToUpdate !== null) {
            studentToUpdate.setName(student.getName());
            console.log(`Student ${student.getRollNo()} updated successfully.`);
            return;
        }
        console.log(`Student ${student.getRollNo()} not found.`);
    }
}

function main() {
    const studentDAO: StudentDAO = new StudentDAOImpl();
    const students: Student[] = studentDAO.getAllStudents();
    console.log("All students: ");
    for (const student of students) {
        console.log(`Name: ${student.getName()}, Roll No: ${student.getRollNo()}`);
    }
    const student: Student = studentDAO.getStudent(2) as Student;
    console.log(`Name: ${student.getName()}, Roll No: ${student.getRollNo()}`);
    student.setName("Jane");
    studentDAO.updateStudent(student);
    console.log("Updated student: ");
    console.log(`Name: ${student.getName()}, Roll No: ${student.getRollNo()}`);
    studentDAO.deleteStudent(student);
    console.log("Deleted student: ");
    console.log(`Name: ${student.getName()}, Roll No: ${student.getRollNo()}`);
}

main();
